package com.topera.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.topera.commonutils.R;
import com.topera.eduservice.entity.EduCourse;
import com.topera.eduservice.entity.EduTeacher;
import com.topera.eduservice.service.EduCourseService;
import com.topera.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;


    /**
     * 前台讲师列表功能
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){

        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map =  teacherService.getTeacherFrontList(pageTeacher);

        return R.ok().data(map);
    }

    /**
     * 获取讲师的详情信息
     * @param id
     * @return
     */
    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id){

        //1、根据讲师id查询讲师基本信息
        EduTeacher teacher = teacherService.getById(id);

        //2、查询讲师所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);

        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
